From: Keir Fraser Date: Wed, 3 Feb 2010 09:46:01 +0000 (+0000) Subject: libxc: Check there's enough memory for segments we're creating X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12653 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=afe765651db2e8f99af74bb8da2a29ee5d923aa6;p=xen.git libxc: Check there's enough memory for segments we're creating Previously, xc_dom_alloc_segment would go ahead even if the segment we're trying to create is too big for the domain's RAM (or the requested addr is out of range). It would pass invalid parameters to xc_dom_seg_to_ptr giving undefined behaviour. Fixing xc_dom_seg_to_ptr to fail is not sufficient because we want to provide a comprehensible explanation to the caller - which may ultimately be the user. In particular, with this change attempting "xl create" with a ramdisk image bigger than the guest's specified RAM will provide a useful error message mentioning the ramdisk. Signed-off-by: Ian Jackson --- diff --git a/tools/libxc/xc_dom_core.c b/tools/libxc/xc_dom_core.c index 23c655efb3..df8e83b6ba 100644 --- a/tools/libxc/xc_dom_core.c +++ b/tools/libxc/xc_dom_core.c @@ -409,8 +409,19 @@ int xc_dom_alloc_segment(struct xc_dom_image *dom, } seg->vstart = start; - seg->vend = start + pages * page_size; seg->pfn = (seg->vstart - dom->parms.virt_base) / page_size; + + if ( pages > dom->total_pages || /* double test avoids overflow probs */ + pages > dom->total_pages - seg->pfn) + { + xc_dom_panic(XC_OUT_OF_MEMORY, + "%s: segment %s too large (0x%"PRIpfn" > " + "0x%"PRIpfn" - 0x%"PRIpfn" pages)\n", + __FUNCTION__, name, pages, dom->total_pages, seg->pfn); + return -1; + } + + seg->vend = start + pages * page_size; dom->virt_alloc_end = seg->vend; if (dom->allocate) dom->allocate(dom, dom->virt_alloc_end);